<template>
  <div id="app">
    <router-view/>
  </div>
</template>
<script>
export default {
  data () {
    return {
    }
  },
  methods: {
    saveVuex () {
      if (Object(this.$store.state.cartInfo ).length> 0) {
        sessionStorage.setItem('cartInfo', JSON.stringify(this.$store.state.cartInfo))
      }
      if (Object.keys(this.$store.state.shopInfo).length > 0) {
        sessionStorage.setItem('shop', JSON.stringify(this.$store.state.shopInfo))
      }
    },
    getVuex () {
      const cartList = sessionStorage.getItem('cartList')
      if (cartList) {
        this.$store.commit('setCartList', JSON.parse(cartList))
      }
      const shop = sessionStorage.getItem('shop')
      if (shop) {
        this.$store.commit('setShopInfo', shop)
      }
    }
  },
  created () {
    this.$nextTick(() => {
      this.getVuex()
    })
    window.onunload = () => {
      this.saveVuex()
    }
  }
}
</script>
<style lang="scss">
</style>
